/*
 * scan.h
 *
 *  Created on: 2010-12-28
 *      Author: root
 */

#ifndef SCAN_H_
#define SCAN_H_
/**********PortScanner.h**************
*
*author :duanjigang @2006-12 <duanjigang1983@126.com>
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
include this file when the program is complied
on a unix os, macro "__LINUX__" was defined in
the Makefile with flag -D
*/
#ifdef __LINUX__
#include <netdb.h>
#endif

#define PROC_TCP "/proc/net/tcp" /*tcp sockets*/
#define PROC_UDP "/proc/net/udp" /*udp sockets*/
#define PROC_TCP6 "/proc/net/tcp6" /*tcp sockets for ipv6*/
#define PROC_UDP6 "/proc/net/udp6" /*udp sockets for ipv6*/

#define ADDR_SIZE 32 /*size  of a char array to
store a 32 BYTE long address*/
#define ERROR_STATUS 0
#define INVALID_PORT -1
/*
define protocol type for our program, just tcp and udp
*/
typedef enum
{
ERROR_PROTO,
UDP_PROTO,
TCP_PROTO
} PROTO_TYPE;


typedef enum
{
  IP_VERSION_ERROR = 0,
  IP_VERSION4 = 4,
  IP_VERSION6 = 6,
} IP_VERSION_TYPE;

/*
define a struct for a (pair of) port(s)
noticed that with a udp sockets, nStatus if of no meaning
*/
struct port
{
char szLocalAddr[ADDR_SIZE]; //local ip addres
char szRemotAddr[ADDR_SIZE]; //remete ip address
IP_VERSION_TYPE nVersion; //ip version
int nLocalPort; //local port
int nRemotPort; //remote port if exists
int nStatus;//status for tcp sockets but not udp sockets
PROTO_TYPE proto; //tcp or udp
};

/*
just cleanup the memory of a  port stuct
return 0 when the pointer is an invalid one
*/
extern int init(struct port * port);
/*
decode contents of data and store all information into
struct port, return 0 when port or data is an invalid pointer
*/
extern int fill_data (struct port * port, const char * data);
/*
get the information in struct port with a user-readable format
if flag equals to 1, the formation is print to the screen too
when it is return in a buffer, we must use type to
decide the format of this string that will be returned and printed
*/
extern char* print (const struct port* port, int flag, PROTO_TYPE type);
/*
array, an array used to store all the port information of a
protocol decided by protocol type
size: the max number of ports can stored in this array
*/
extern int get_port_list(struct port * array, int size, PROTO_TYPE type);

/*
deal with input parameters
*/

#endif /* SCAN_H_ */
